﻿using System;
using System.Data;
using System.Collections.Generic;
using Common;
using Model;
namespace BLL
{
	/// <summary>
	/// 走访结果
	/// </summary>
	public partial class Volunteer_Apply
	{
		private readonly DAL.Volunteer_Apply dal=new DAL.Volunteer_Apply();
		public Volunteer_Apply()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Model.Volunteer_Apply model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.Volunteer_Apply model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.Volunteer_Apply GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Model.Volunteer_Apply GetModelByCache(int Id)
		{
			
			string CacheKey = "Volunteer_ApplyModel-" + Id;
			object objModel = Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = Common.ConfigHelper.GetConfigInt("ModelCache");
						Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Model.Volunteer_Apply)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Model.Volunteer_Apply> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Model.Volunteer_Apply> DataTableToList(DataTable dt)
		{
			List<Model.Volunteer_Apply> modelList = new List<Model.Volunteer_Apply>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Model.Volunteer_Apply model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Model.Volunteer_Apply();
					if(dt.Rows[n]["Id"]!=null && dt.Rows[n]["Id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
					}
					if(dt.Rows[n]["Email"]!=null && dt.Rows[n]["Email"].ToString()!="")
					{
					model.Email=dt.Rows[n]["Email"].ToString();
					}
					if(dt.Rows[n]["Name"]!=null && dt.Rows[n]["Name"].ToString()!="")
					{
					model.Name=dt.Rows[n]["Name"].ToString();
					}
					if(dt.Rows[n]["Age"]!=null && dt.Rows[n]["Age"].ToString()!="")
					{
						model.Age=int.Parse(dt.Rows[n]["Age"].ToString());
					}
					if(dt.Rows[n]["Sex"]!=null && dt.Rows[n]["Sex"].ToString()!="")
					{
					model.Sex=dt.Rows[n]["Sex"].ToString();
					}
					if(dt.Rows[n]["PhoneNumber"]!=null && dt.Rows[n]["PhoneNumber"].ToString()!="")
					{
					model.PhoneNumber=dt.Rows[n]["PhoneNumber"].ToString();
					}
					if(dt.Rows[n]["QQ"]!=null && dt.Rows[n]["QQ"].ToString()!="")
					{
					model.QQ=dt.Rows[n]["QQ"].ToString();
					}
					if(dt.Rows[n]["DistrictId"]!=null && dt.Rows[n]["DistrictId"].ToString()!="")
					{
						model.DistrictId=int.Parse(dt.Rows[n]["DistrictId"].ToString());
					}
					if(dt.Rows[n]["Slogan"]!=null && dt.Rows[n]["Slogan"].ToString()!="")
					{
					model.Slogan=dt.Rows[n]["Slogan"].ToString();
					}
					if(dt.Rows[n]["IsReject"]!=null && dt.Rows[n]["IsReject"].ToString()!="")
					{
						if((dt.Rows[n]["IsReject"].ToString()=="1")||(dt.Rows[n]["IsReject"].ToString().ToLower()=="true"))
						{
						model.IsReject=true;
						}
						else
						{
							model.IsReject=false;
						}
					}
					if(dt.Rows[n]["InsTime"]!=null && dt.Rows[n]["InsTime"].ToString()!="")
					{
						model.InsTime=DateTime.Parse(dt.Rows[n]["InsTime"].ToString());
					}
					if(dt.Rows[n]["IsPass"]!=null && dt.Rows[n]["IsPass"].ToString()!="")
					{
						if((dt.Rows[n]["IsPass"].ToString()=="1")||(dt.Rows[n]["IsPass"].ToString().ToLower()=="true"))
						{
						model.IsPass=true;
						}
						else
						{
							model.IsPass=false;
						}
					}
					if(dt.Rows[n]["Remark"]!=null && dt.Rows[n]["Remark"].ToString()!="")
					{
					model.Remark=dt.Rows[n]["Remark"].ToString();
					}
					if(dt.Rows[n]["DisposeTime"]!=null && dt.Rows[n]["DisposeTime"].ToString()!="")
					{
						model.DisposeTime=DateTime.Parse(dt.Rows[n]["DisposeTime"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

